<?php

namespace App\Console\Commands;

use App\Api\Account\Models\ChatMessage;
use App\Api\Account\Models\CommitTag;
use App\Api\Account\Models\UserCommit;
use App\Api\Sport\Models\CouponCodes;
use App\Api\Sport\Models\CpResultsFinal;
use App\Api\Sport\Models\Cps;
use App\Api\Sport\Models\GroupTeam;
use App\Api\Sport\Models\Players;
use App\Api\Sport\Models\SignUpOrders;
use App\Api\Sport\Services\SportService;
use App\Libs\AiText\XunfeiAi;
use App\Libs\Wechat\WechatService;
use App\User;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use OSS\Core\OssException;
use OSS\OssClient;
use Qiniu\Auth;
use Qiniu\Storage\BucketManager;

class Fix extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'ff';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Display an inspiring quote';

    /**
     * Execute the console command.
     *
     * @return mixed
     */

    public function handle()
    {
//        $a = 123.321;
//        echo is_numeric($a);exit;
//        $r = parse_url('/pages/views/detail/detail?id=39&share_user_id=0');
//        print_r($r);exit;
        $wechat  = new WechatService(config('payment.jueqiweilaixcx.wechat.app_id'), config('payment.jueqiweilaixcx.wechat.app_secret'));
        $access_token = $wechat->msgSecCheck('老赵他中午插起来吃太多太爽了，下午就后入一直大屁股', 'ogfC_5X6AgClrKiyhTivdJL0ruB4');
        print_r($access_token);exit;
        exit;
        print_r($access_token);
        $a = UserCommit::get();
        foreach ($a as $v) {
            $r = CommitTag::find(data_get($v, 'commit_tag_id'));
            $v->update([
                'commit_tag_name' => data_get($r, 'tag')
            ]);
        }
        exit;
        $params['photos'] = [] ;
        $updates = [];
        $photos = data_get($params, 'photos', []);
        if (is_array($photos) && !empty($photos)) {
//            foreach ($photos as $k => $photo) {
//                $photos[$k] = $photo;
//            }
            $photosStr = json_encode($photos);
            empty($photosStr) ? : $updates['photos'] = $photosStr;
        }
        print_r($updates);exit;
        $a = [];
        echo !empty($a);exit;
        $a = User::get();
        foreach ($a as $v) {
            User::find($v->id)
                ->update(['share_id' => str_random(10)]);
        }
        exit;
        $r = \DB::table('users_open_ids')
            ->where('id', '=', '56823')
            ->decrement('notify_count');
        print_r($r);exit;
        $y="1800";
        $x = array();
        for($j=0;$j<2000;$j++){
            $x[]= "{$j}";
        }
        for($i=0;$i<3000;$i++){
            if(in_array($y,$x,true)){
                continue;
            }
        }


        $y="1800";
        $x = array();
        for($j=0;$j<2000;$j++){
            $x[]= "{$j}";
        }

        for($i=0;$i<3000;$i++){
            if(in_array($y,$x)){
                continue;
            }
        }
        exit;
        $template_id = '-Dk0UIdNn5JhC5FcCwhVpr8_KppV4LegtUOb30Z_qnY';
//        $access_token = '50_ih086I9wDlTpBxCauarKVKGYE3oy-IAvKdWSKHNi8L2i3HzKiwkGDNl323anJW4MCwLHnl2SVe2J9EY1UxvAIqReW-USwsSp5wnAWc6CQ_6QTvTAZmh35SiuCKXg_v0ImGFwrdv1zUtlDPVrVDAaAGAYGD';

        $wechat  = new WechatService(config('payment.jueqiweilaixcx.wechat.app_id'), config('payment.jueqiweilaixcx.wechat.app_secret'));
        $access_token = $wechat->getAccessToken();
        print_r($access_token);
//        $url='https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$access_token;
        $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='.$access_token;
//        $url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token='.$access_token;
        $color = '#173177';
        $params['touser'] = 'oNtLy4tJ2Gp3JIcC49wKusmnEaOI';
        $params['template_id'] = $template_id;
        $params['page'] = 'pages/views/index/index';
        $params['miniprogram_state'] = 'trial';
//        $params['weapp_template_msg'] = [];
//        $params['weapp_template_msg']['template_id'] = $template_id;
//        $params['weapp_template_msg']['page'] = '123';
//        $params['weapp_template_msg']['form_id'] = '17648';
//        $params['weapp_template_msg']['emphasis_keyword'] = 'keyword1.DATA';
//        $params['weapp_template_msg']['data'] = '17648';
//        $params['data']['first'] = [
//            'value'=>$param['first'],
//            'color'=>$color,
//        ];
        $params['data']['thing1'] = [
            'value'=>str_random(3),
//            'color'=>$color,
        ];
        $params['data']['thing2'] = [
                'value'=>str_random(3),
//                'color'=>$color,
            ];
        $params['data']['time3'] = [
                'value'=>Carbon::now()->toDateTimeString(),
//                'color'=>$color,
            ];
        $params['data']['thing4'] = [
                'value'=>str_random(3),
//                'color'=>$color,
            ];
        $params['data']['thing5'] = [
                'value'=>str_random(3),
//                'color'=>$color,
            ];
//            print_r($params);exit;
        $res = postJson($url, $params)->getBody()->getContents();
        print_r($res);exit;
        info('微信模板消息', [$res]);
        return $res;
        $messages = ChatMessage::where('chat_id', '!=', 123123)
            ->orderBy('id', 'desc')
            ->paginate(20, ['*'], 'page', 1)
            ->toArray();


        print_r(array_pluck($messages['data'], 'id'));exit;
        $a = [
            ['id'=>1,],
            ['id'=>2,],
            ['id'=>3,],
            ['id'=>4,],
        ];
        $r = array_pluck($a, 'id');
        print_r($r);exit;
        $config = config('vip.products', []);
//        print_r($config);exit;
        $productId = '2';
        $r = collect($config)->where('id', (string)$productId)->first();
        print_r($r);exit;
//        116.412534,39.911337
        //121.481827,37.44328
        $lng = 121.481827;//经度
        $lat = 37.44328;//纬度
        $sql = "select *, from community order by distance asc limit 1,10";
        $r = \DB::select($sql);
        print_r($r);exit;


        //select *,(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(111.86141967773438-lng)/360),2)+COS(PI()*33.07078170776367/180)* COS(lat * PI()/180)*POW(SIN(PI()*(33.07078170776367-lat)/360),2)))) as juli from `area`order by juli asc limit 0,20
        $r = distance(116.187314, 40.022903, 116.783323,40.05024);
        print_r($r);exit;
        $r = upload2Qiniu(base_path('a.pdf'), 'rent-testw');
        print_r($r);exit;
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

#use OSS\OssClient;
#use OSS\Core\OssException;

// 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维，请登录RAM控制台创建RAM账号。
$accessKeyId = "LTAI5tCHnZM9TPZtH2JFeZtR";
$accessKeySecret = "NtnrZeCEPNInHYtayRPQj8snvC08CV";
// Endpoint以杭州为例，其它Region请按实际情况填写。
$endpoint = "http://oss-cn-beijing.aliyuncs.com";
// 设置存储空间名称。
$bucket= "rent-test";
// 设置文件名称。
$object = "a.pdf";
// <yourLocalFile>由本地文件路径加文件名包括后缀组成，例如/users/local/myfile.txt。
$filePath = base_path('a.pdf');

try{
    $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);

    $r = $ossClient->uploadFile($bucket, $object, $filePath);
    print_r($r);
} catch(OssException $e) {
    printf(__FUNCTION__ . ": FAILED\n");
    printf($e->getMessage() . "\n");
    return;
}
print(__FUNCTION__ . ": OK" . "\n");
    }
}
